using System;
using System.Reflection;
using Microsoft.SharePoint;

namespace SharePoint.DataMapper
{
	[FieldMapper(typeof(SPFieldText), SPFieldType.Text)]
	public class FieldTextMapper : FieldMapper
	{
		protected override SPField AddFieldInternal(ListDataContext context, SPFieldCollection collection, Type propertyType, FieldAttribute attribute)
		{
			SPFieldText field = (SPFieldText)base.AddFieldInternal(context, collection, propertyType, attribute);
			field.MaxLength = attribute.MaxLength;
			return field;
		}

		protected override FieldAttribute GetFieldAttributeInternal(SPField field)
		{
			FieldAttribute attribute = base.GetFieldAttributeInternal(field);

			SPFieldText fieldText = field as SPFieldText;
			if (fieldText == null)
			{
				return attribute;
			}
			attribute.MaxLength = fieldText.MaxLength;
			return attribute;
		}
	}
}